<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    要求监听name的改变  <hr>
    <button @click="setName"> 修改 </button>
    <p> {{ people.name }} </p>
  </div>
</body>
<script src="../../lib/vue.global.js"></script>
<script>
  Vue.createApp({
    data () {
      return {
        people: {
          name: 'lakers'
        }
      }
    },
    watch: {
      // 结论： watch 默认只能监听一层数据 
      // people () {
      //   console.log('name改变了')
      // }

      people: {
        deep: true, // 开启深度监听
        immediate: true,//表示立即执行
        handler (newPeople) { // handler 这个方法名不能改
          console.log(newPeople.name)
        }
      }
    },
    methods: {
      setName () {
        this.people.name = 'unicorn'
      }
    }
  }).mount('#app')
</script>
</html>